package com.ruoyi.mall.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.ApiResult;
import com.ruoyi.mall.domain.MallTimeWarehouse;
import com.ruoyi.mall.mapper.MallTimeWarehouseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallCouponMapper;
import com.ruoyi.mall.domain.MallCoupon;
import com.ruoyi.mall.service.IMallCouponService;

/**
 * 优惠券Service业务层处理
 *
 * @author ruoyi
 * @date 2021-12-17
 */
@Service
public class MallCouponServiceImpl implements IMallCouponService
{
    @Autowired
    private MallCouponMapper mallCouponMapper;
    @Autowired
    private MallTimeWarehouseMapper mallTimeWarehouseMapper;

    /**
     * 查询优惠券
     *
     * @param id 优惠券主键
     * @return 优惠券
     */
    @Override
    public MallCoupon selectMallCouponById(Long id)
    {
        return mallCouponMapper.selectMallCouponById(id);
    }

    /**
     * 查询优惠券列表
     *
     * @param mallCoupon 优惠券
     * @return 优惠券
     */
    @Override
    public List<MallCoupon> selectMallCouponList(MallCoupon mallCoupon)
    {
        return mallCouponMapper.selectMallCouponList(mallCoupon);
    }

    /**
     * 新增优惠券
     *
     * @param mallCoupon 优惠券
     * @return 结果
     */
    @Override
    public int insertMallCoupon(MallCoupon mallCoupon)
    {
        if (mallCoupon.getRegionId() != null) {
            MallTimeWarehouse timeWarehouse = mallTimeWarehouseMapper.selectMallTimeWarehouseById(mallCoupon.getRegionId());
            if (timeWarehouse != null) {
                mallCoupon.setRegionName(timeWarehouse.getTitle());
            }
        }
        return mallCouponMapper.insertMallCoupon(mallCoupon);
    }

    /**
     * 修改优惠券
     *
     * @param mallCoupon 优惠券
     * @return 结果
     */
    @Override
    public int updateMallCoupon(MallCoupon mallCoupon)
    {
        if (mallCoupon.getRegionId() != null) {
            MallTimeWarehouse timeWarehouse = mallTimeWarehouseMapper.selectMallTimeWarehouseById(mallCoupon.getRegionId());
            if (timeWarehouse != null) {
                mallCoupon.setRegionName(timeWarehouse.getTitle());
            }
        }
        return mallCouponMapper.updateMallCoupon(mallCoupon);
    }

    /**
     * 批量删除优惠券
     *
     * @param ids 需要删除的优惠券主键
     * @return 结果
     */
    @Override
    public int deleteMallCouponByIds(Long[] ids)
    {
        return mallCouponMapper.deleteMallCouponByIds(ids);
    }

    /**
     * 删除优惠券信息
     *
     * @param id 优惠券主键
     * @return 结果
     */
    @Override
    public int deleteMallCouponById(Long id)
    {
        return mallCouponMapper.deleteMallCouponById(id);
    }

    @Override
    public List<Map<String, Object>> selectMallCouponVOList() {
        return mallCouponMapper.selectMallCouponVOList();
    }
}
